/*
 * @Author: 张笑天
 * @Date: 2018-03-07 17:08:57
 * @Last Modified by: lyuan2018
 * @Last Modified time: 2020-08-20 15:39:25
 */
import React from 'react';
import { Popover, Button } from 'antd';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

export default class PopoverTodo extends React.Component {
  constructor(props) {
    super(props);
    this.prefixClass = 'wea-email-popover-todo';
  }
  onTodoClick = (params = {}) => {
    const { onTodoClick } = this.props;
    typeof onTodoClick === 'function' && onTodoClick(params);
    this.hide();
  };
  onTodoComplete = () => {
    const { onTodoComplete } = this.props;
    typeof onTodoComplete === 'function' && onTodoComplete();
    this.hide();
  };
  hide = () => {
    this.refs.todo.refs.tooltip.setState({ visible: false });
  };
  onAddRemind = () => this.onTodoClick({ op_hasRemind: 1 });
  onAddNote = () => this.onTodoClick({ op_hasNote: 1 });
  getProps = ({
    mailId,
    waitdeal,
    waitdealtime,
    op_hasNote,
    wdremindtime,
    waitdealnote,
    op_hasRemind,
    waitdealway,
  }) => ({
    ref: 'todo',
    trigger: 'click',
    overlayClassName: `${this.prefixClass}`,
    placement: 'bottomRight',
    title: (
      <div className={`${this.prefixClass}-title`}>
        {waitdeal ? `${getLabel(384330, '已设置为待办邮件')},` : null}
        <span>
          {waitdealtime}
          {getLabel('553', '处理')}
        </span>
        <i className="icon-email-edit" onClick={this.onTodoClick} />
        <Button
          ecId={`${
            (this && this.props && this.props.ecId) || ''
          }_Button@5vzcms`}
          type="ghost"
          onClick={() => this.onTodoComplete(mailId)}
        >
          <i className="icon-email-complete" />
          {getLabel(83112, '设为完成')}
        </Button>
      </div>
    ),
    content: (
      <div className={`${this.prefixClass}-content`}>
        {op_hasRemind && waitdealway ? (
          <p className={`${this.prefixClass}-content-show`}>
            <span>{getLabel(18713, '提醒方式')}:</span>
            {waitdealway == '5'
              ? getLabel('383607', '消息中心提醒')
              : waitdealway == '1'
              ? getLabel('17586', '短信提醒')
              : getLabel('510271', '消息中心提醒，短信提醒')}
          </p>
        ) : null}
        {op_hasRemind && wdremindtime ? (
          <p className={`${this.prefixClass}-content-show`}>
            <span>{getLabel(785, '提醒时间')}:</span>
            {wdremindtime}
          </p>
        ) : (
          <p className={`${this.prefixClass}-content-btn`}>
            <span onClick={this.onAddRemind}>
              <i className="icon-email-remind" />
              {getLabel(83135, '添加提醒')}
            </span>
          </p>
        )}
        {op_hasNote && waitdealnote ? (
          <p
            className={`${this.prefixClass}-content-show`}
            style={{ paddingLeft: 33 }}
          >
            <span style={{ marginLeft: -33 }}>
              {getLabel('26408', '备注')}:
            </span>
            {waitdealnote}
          </p>
        ) : (
          <p className={`${this.prefixClass}-content-btn`}>
            <span onClick={this.onAddNote}>
              <i className="icon-email-Remarks" />
              {getLabel(83136, '添加备注')}
            </span>
          </p>
        )}
      </div>
    ),
  });
  render() {
    return (
      <Popover
        ecId={`${(this && this.props && this.props.ecId) || ''}_Popover@bbffqf`}
        {...this.getProps(this.props.data)}
      >
        {this.props.children}
      </Popover>
    );
  }
}
